package com.liws.hellojuc.reentrantLock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author ：liweisheng
 * @date ：2022/1/31 6:45
 * @description： reentrantLock的简单例子
 */
public class ReentrantLockTest01 {

    private static final Lock lock=new ReentrantLock();
    public static void main(String[] args) {
        new Thread(()->test(),"线程A").start();

    }
    public static void  test(){
        lock.lock();
        System.out.println(Thread.currentThread().getName()+"获取了锁");
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            System.out.println(Thread.currentThread().getName()+"释放了锁");
            lock.unlock();

        }
    }
}
